package com.kaifamiao.thread.d0927;

import java.time.LocalTime;
import java.util.concurrent.*;

public class Demo07 {

    public static void main(String[] args) {
//        ThreadPoolExecutor cached = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<>());

//        ThreadPoolExecutor fixed = new ThreadPoolExecutor(3, 3, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());

//        ThreadPoolExecutor; single = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(2, 2, 4L, TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(2), new ThreadPoolExecutor.DiscardPolicy());
        poolExecutor.allowCoreThreadTimeOut(true);

        for (int i = 0; i < 10; i++) {
            int number = i;
            poolExecutor.execute(() -> {
                System.out.println("当前时间:" + LocalTime.now() + ", 线程: " + Thread.currentThread().getName() + ", 序号：" + number);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
        }
    }
}
